﻿/*********************************************************
 * copyright learnren.com 版权所有
 * 开发人员：minyuan
 * 创建时间：2013/6/30 15:20:58
 * 描述说明：
 * 
 * 更改历史：
 * 
 * *******************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LEARNREN.COM.TOOL;
using LEARNREN.COM.BLL;
using System.IO;

namespace LEARNREN.COM.UI
{
    public abstract class BaseTemplatePage : BasePage
    {
        /// <summary>
        /// 逻辑处理对象缓存池，key：标签头，value：逻辑处理对象
        /// </summary>
        protected Dictionary<string, ILogic> logicDic = null;

        /// <summary>
        /// 当前页面的模板文件名称
        /// </summary>
        protected string templateFileName = null;

        private string _DefaultTemplateFolder = null;

        /// <summary>
        /// 获取使用的模板所在文件夹
        /// </summary>
        protected string DefaultTemplateFolder
        {
            get
            {
                if (string.IsNullOrEmpty(_DefaultTemplateFolder))
                {
                    string result = UtilityTool.GetConfiguration("template");

                    if (string.IsNullOrEmpty(result))
                    {
                        result = Server.MapPath("~/Templates/DefaultTemplates/");
                    }
                    else
                    {
                        result = Server.MapPath(result);
                    }

                    _DefaultTemplateFolder = result;
                }
                return _DefaultTemplateFolder;
            }
        }

        protected override void InitLogic()
        {
            logicDic = new Dictionary<string, ILogic>();
        }

        protected override void DisposeLogic()
        {
            if (logicDic != null)
            {
                foreach (var logic in logicDic.Values)
                {
                    if (logic != null)
                    {
                        logic.Dispose();
                    }
                }
            }
        }

        #region 私有方法

        private void GetLabels()
        {
            string tmpFile = Path.Combine(DefaultTemplateFolder, templateFileName);
            if (!File.Exists(tmpFile))
            {
                throw new FileNotFoundException("Could not find the template file!");
            }
            try
            {
                string tmpString = File.ReadAllText(tmpFile);

            }
            catch (Exception ex)
            {
                
                throw;
            }
        }

        #endregion 私有方法
    }
}
